<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Chapter2 Python知识汇总 | 小蓝哥的知识荒原</title>
<meta name="author" content="李详">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.2"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.9/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><script src="libs/bs3compat-0.2.5.1/tabs.js"></script><script src="libs/bs3compat-0.2.5.1/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><script src="https://cdn.jsdelivr.net/autocomplete.js/0/autocomplete.jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/mark.js@8.11.1/dist/mark.min.js"></script><!-- CSS -->
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-3 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <h1>
        <a href="index.html" title="">小蓝哥的知识荒原</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>

      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">简介</a></li>
<li><a class="" href="r.html"><span class="header-section-number">1</span> R语言知识汇总</a></li>
<li><a class="active" href="python.html"><span class="header-section-number">2</span> Python知识汇总</a></li>
<li><a class="" href="bioinf.html"><span class="header-section-number">3</span> 生物信息学</a></li>
<li><a class="" href="literature.html"><span class="header-section-number">4</span> 嗑盐文献</a></li>
<li><a class="" href="article.html"><span class="header-section-number">5</span> 嗑盐文章</a></li>
<li><a class="" href="%E4%B8%8A%E8%AF%BE%E7%AC%94%E8%AE%B0.html"><span class="header-section-number">6</span> 上课笔记</a></li>
<li><a class="" href="other.html"><span class="header-section-number">7</span> Other</a></li>
<li><a class="" href="references.html">References</a></li>
</ul>

        <div class="book-extra">
          <p><a id="book-repo" href="https://github.com/lixiang117423/lixiang117423.github.io">View book source <i class="fab fa-github"></i></a></p>
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="python" class="section level1" number="2">
<h1>
<span class="header-section-number">Chapter2</span> Python知识汇总<a class="anchor" aria-label="anchor" href="#python"><i class="fas fa-link"></i></a>
</h1>
<div id="本章前言-1" class="section level2" number="2.1">
<h2>
<span class="header-section-number">2.1</span> 本章前言<a class="anchor" aria-label="anchor" href="#%E6%9C%AC%E7%AB%A0%E5%89%8D%E8%A8%80-1"><i class="fas fa-link"></i></a>
</h2>
<p>本章主要是关于Python的相关知识，包括Python基础知识、数据统计分析、数据可视化及人工只能等内容。</p>
</div>
<div id="fasta文件处理" class="section level2" number="2.2">
<h2>
<span class="header-section-number">2.2</span> <code>fasta</code>文件处理<a class="anchor" aria-label="anchor" href="#fasta%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86"><i class="fas fa-link"></i></a>
</h2>
<div id="处理从planttfdb下载的序列" class="section level3" number="2.2.1">
<h3>
<span class="header-section-number">2.2.1</span> 处理从PlantTFDB下载的序列<a class="anchor" aria-label="anchor" href="#%E5%A4%84%E7%90%86%E4%BB%8Eplanttfdb%E4%B8%8B%E8%BD%BD%E7%9A%84%E5%BA%8F%E5%88%97"><i class="fas fa-link"></i></a>
</h3>
<div class="sourceCode" id="cb17"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb17-1"><a href="python.html#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> os</span>
<span id="cb17-2"><a href="python.html#cb17-2" aria-hidden="true" tabindex="-1"></a>os.chdir(<span class="st">"C://Users//Administrator//Desktop//"</span>)</span>
<span id="cb17-3"><a href="python.html#cb17-3" aria-hidden="true" tabindex="-1"></a><span class="co">#read txt method one</span></span>
<span id="cb17-4"><a href="python.html#cb17-4" aria-hidden="true" tabindex="-1"></a>wrky_seq <span class="op">=</span> <span class="bu">open</span>(<span class="st">'wrky_seq.fasta'</span>,<span class="st">'w'</span>)</span>
<span id="cb17-5"><a href="python.html#cb17-5" aria-hidden="true" tabindex="-1"></a>wrky_info <span class="op">=</span> <span class="bu">open</span>(<span class="st">'wrky_info.txt'</span>,<span class="st">'w'</span>)</span>
<span id="cb17-6"><a href="python.html#cb17-6" aria-hidden="true" tabindex="-1"></a>f <span class="op">=</span> <span class="bu">open</span>(<span class="st">"seq.fas"</span>,<span class="st">'r'</span>)</span>
<span id="cb17-7"><a href="python.html#cb17-7" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> line <span class="kw">in</span> f:</span>
<span id="cb17-8"><a href="python.html#cb17-8" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="bu">str</span>.startswith(line,<span class="st">"&gt;"</span>):</span>
<span id="cb17-9"><a href="python.html#cb17-9" aria-hidden="true" tabindex="-1"></a>        seq_name <span class="op">=</span> <span class="bu">str</span>.split(line, <span class="st">'|'</span>)[<span class="dv">0</span>]</span>
<span id="cb17-10"><a href="python.html#cb17-10" aria-hidden="true" tabindex="-1"></a>        <span class="co">#seq_name = str.split(seq_name,'.')[0]</span></span>
<span id="cb17-11"><a href="python.html#cb17-11" aria-hidden="true" tabindex="-1"></a>        seq_species <span class="op">=</span> <span class="bu">str</span>.split(line, <span class="st">'|'</span>)[<span class="dv">1</span>]</span>
<span id="cb17-12"><a href="python.html#cb17-12" aria-hidden="true" tabindex="-1"></a>        seq_name2 <span class="op">=</span> <span class="bu">str</span>.replace(seq_name, <span class="st">"&gt;"</span>, <span class="st">""</span>)</span>
<span id="cb17-13"><a href="python.html#cb17-13" aria-hidden="true" tabindex="-1"></a>        <span class="co">#print(seq_name)</span></span>
<span id="cb17-14"><a href="python.html#cb17-14" aria-hidden="true" tabindex="-1"></a>        wrky_seq.write(seq_name <span class="op">+</span> <span class="st">"</span><span class="ch">\n</span><span class="st">"</span>)</span>
<span id="cb17-15"><a href="python.html#cb17-15" aria-hidden="true" tabindex="-1"></a>        wrky_info.write(seq_name <span class="op">+</span> <span class="st">"    "</span> <span class="op">+</span> seq_name2 <span class="op">+</span> <span class="st">"    "</span> <span class="op">+</span> seq_species <span class="op">+</span> <span class="st">"</span><span class="ch">\n</span><span class="st">"</span>)</span>
<span id="cb17-16"><a href="python.html#cb17-16" aria-hidden="true" tabindex="-1"></a>    <span class="cf">else</span>:</span>
<span id="cb17-17"><a href="python.html#cb17-17" aria-hidden="true" tabindex="-1"></a>        wrky_seq.write(line)</span>
<span id="cb17-18"><a href="python.html#cb17-18" aria-hidden="true" tabindex="-1"></a>wrky_seq.close()</span>
<span id="cb17-19"><a href="python.html#cb17-19" aria-hidden="true" tabindex="-1"></a>wrky_info.close()</span></code></pre></div>

</div>
</div>
</div>
  <div class="chapter-nav">
<div class="prev"><a href="r.html"><span class="header-section-number">1</span> R语言知识汇总</a></div>
<div class="next"><a href="bioinf.html"><span class="header-section-number">3</span> 生物信息学</a></div>
</div></main><div class="col-md-3 col-lg-2 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#python"><span class="header-section-number">2</span> Python知识汇总</a></li>
<li><a class="nav-link" href="#%E6%9C%AC%E7%AB%A0%E5%89%8D%E8%A8%80-1"><span class="header-section-number">2.1</span> 本章前言</a></li>
<li>
<a class="nav-link" href="#fasta%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86"><span class="header-section-number">2.2</span> fasta文件处理</a><ul class="nav navbar-nav"><li><a class="nav-link" href="#%E5%A4%84%E7%90%86%E4%BB%8Eplanttfdb%E4%B8%8B%E8%BD%BD%E7%9A%84%E5%BA%8F%E5%88%97"><span class="header-section-number">2.2.1</span> 处理从PlantTFDB下载的序列</a></li></ul>
</li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
<li><a id="book-source" href="https://github.com/lixiang117423/lixiang117423.github.io/blob/master/002-Python.Rmd">View source <i class="fab fa-github"></i></a></li>
          <li><a id="book-edit" href="https://github.com/lixiang117423/lixiang117423.github.io/edit/master/002-Python.Rmd">Edit this page <i class="fab fa-github"></i></a></li>
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

  <div class="col-12 col-md-6 mt-3">
    <p>"<strong>小蓝哥的知识荒原</strong>" was written by 李详. It was last built on 2021年10月1日.</p>
  </div>

  <div class="col-12 col-md-6 mt-3">
    <p>This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
  </div>

</div></div>
</footer><!-- dynamically load mathjax for compatibility with self-contained --><script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>
</html>
